import { Container } from '../Container';
import { HelperTool } from './Common';
import { DataService } from "./DataService";
import { SettingService } from './SettingService';
import { ViewerService } from "./ViewerService";


export class ViewPointManService {
    ViewerService = Container.defineProperty(ViewerService);
    DataService = Container.defineProperty(DataService);
    settingService = Container.defineProperty(SettingService);
    getData(): ViewPoint[] {
        if (!this.DataService.Data.views) {
            this.DataService.Data.views = [];
        }
        return this.DataService.Data.views;
    }

    viewSelect(index: number) {
        let array = this.getData();
        this.ViewerService.viewer.restoreState(array[index].view);
    }

    getViewerState(viewPoint: ViewPoint) {
        viewPoint.view = this.ViewerService.viewer.getState();
        viewPoint.setting = HelperTool.Clone(this.settingService.getData().setting);
    }
    restoreViewerState(viewPoint: ViewPoint) {
        this.ViewerService.viewer.restoreState(viewPoint.view);
        if (viewPoint.setting){
            Object.assign(this.settingService.getData().setting, viewPoint.setting);
            this.settingService.updateViewer();
            this.settingService.DataChanged.dispatchEvent();
        }
    }
}
export type ViewPoint = {
    name: string,
    view: any,
    setting?: any,
}
